import {
    totalConfig,
    propName
} from 'server/config/templateConfig';
import utils from 'server/core/utils';

let mapConfig = totalConfig.map;
let buildingConfig = totalConfig.building;

//地图信息
export default function MapInfo(originMapInfos) {
    let data = {};

    for (let i in mapConfig) {
        let building = {}
        if (mapConfig[i].building) {
            mapConfig[i].building.forEach(buildingId => {
                building[buildingId] = {
                    hide: buildingConfig[buildingId].hide,
                    item: Object.assign({}, buildingConfig[buildingId].item)
                };
            });
        }
        data[i] = {
            //1.临时的建筑,用了就没了 2.一直就有的建筑 3.跟进条件加上来的建筑(后一直存在)
            building: building,
            buildingForever: {},
            show: false,
        }
    }
    let map = {};
    if (originMapInfos) {
        for (let i in data) {
            if (originMapInfos[i]) {
                let building = {}
                if (mapConfig[i].building) {
                    mapConfig[i].building.forEach(buildingId => {
                        if (originMapInfos[i].building && !originMapInfos[i].building[buildingId]) {
                            building[buildingId] = {
                                hide: buildingConfig[buildingId].hide
                            };
                            if (buildingConfig[buildingId].item) {
                                building[buildingId].item = Object.assign({}, buildingConfig[buildingId].item);
                            }
                        } else if (originMapInfos[i].building && originMapInfos[i].building[buildingId]) {
                            building[buildingId] = originMapInfos[i].building[buildingId];
                        } else {
                            building[buildingId] = {
                                hide: buildingConfig[buildingId].hide
                            };
                            if (buildingConfig[buildingId].item) {
                                building[buildingId].item = Object.assign({}, buildingConfig[buildingId].item);
                            }
                        }
                    });
                }
                map[i] = {
                    building: building,
                    buildingForever: originMapInfos[i].buildingForever || {},
                    show: originMapInfos[i].show,
                };
            } else {
                map[i] = data[i];
            }
        }
    } else {
        map = data;
    }
    return map;
}